<template>
  <div class="proListItem" @click="proItemClick">
    <img v-lazy="showImage" alt="" @load="imageLoad" />
    <div class="proListItem_info">
      <p>{{proListItem.title}}</p>
      <span class="price">{{proListItem.price}}</span>
      <span class="collect">{{proListItem.cfav}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "ProListItem",
    props: {
      proListItem: {
        type: Object,
        default() {
          return {}
        }
      }
    },
    computed: {
      showImage() {
        return this.proListItem.image || this.proListItem.show.img
      }
    },
    methods: {
      imageLoad() {
        //通过事件总线（$bus）将事件发射出去，由首页负责监听
        //默认情况下$bus为undefined，需要在入口js(main.js)中new一个vue实例
          this.$bus.$emit('itemImgLoad')
      },
      //点击对应的商品列表时携带对应的id跳转到详情页
      proItemClick() {
        this.$router.push('/Detail/' + this.proListItem.iid)
      }
    }
  }
</script>

<style scoped>
  .proListItem {
    padding-bottom: 40px;
    position: relative;
    width: 48%;
  }

  .proListItem img {
    width: 100%;
    border-radius: 5px;
  }

  .proListItem_info {
    font-size: 12px;
    position: absolute;
    bottom: 5px;
    left: 0;
    right: 0;
    overflow: hidden;
    text-align: center;
  }

  .proListItem_info p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
  }

  .proListItem_info .price {
    color: var(--color-high-text);
    margin-right: 20px;
  }
  .proListItem_info .collect {
    position: relative;
  }
  .proListItem_info .collect::before {
    content: '';
    position: absolute;
    left: -15px;
    top: -1px;
    width: 14px;
    height: 14px;
    background: url('../../../assets/images/common/collect.svg') 0 0/14px 14px;
  }
</style>
